<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="100px">
      <el-form-item label="车位编号" prop="parkspaceName">
        <el-input
          v-model="queryParams.parkspaceName"
          placeholder="请输入车位编号"
          clearable
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="设备SN" prop="deviceSn">
        <el-input
          v-model="queryParams.deviceSn"
          placeholder="请输入SIM卡号"
          clearable
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="车位状态" prop="parkspaceStatus">
        <el-select
          v-model="queryParams.parkspaceStatus"
          placeholder="请选择车位状态"
          clearable
          style="width: 240px"
        >
          <el-option
            v-for="dict in dict.type.berth_park_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="地磁状态" prop="sMs">
        <el-input
          v-model="queryParams.sMs"
          placeholder="请输入地磁状态"
          clearable
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="flash状态" prop="sFs">
        <el-input
          v-model="queryParams.sFs"
          placeholder="请输入flash状态"
          clearable
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="蓝牙状态" prop="sBle">
        <el-input
          v-model="queryParams.sBle"
          placeholder="请输入蓝牙状态"
          clearable
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="硬件版本" prop="hwVer">
        <el-input
          v-model="queryParams.hwVer"
          placeholder="请输入硬件版本"
          clearable
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="软件版本" prop="swVer">
        <el-input
          v-model="queryParams.swVer"
          placeholder="请输入软件版本"
          clearable
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="在线状态" prop="linkStatus">
        <el-select
          v-model="queryParams.linkStatus"
          placeholder="请选择在线状态"
          clearable
          style="width: 240px"
        >
          <el-option
            v-for="dict in dict.type.comm_online_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="更新时间" prop="dateRange">
        <el-date-picker
          v-model="queryParams.dateRange"
          style="width: 333px"
          value-format="yyyy-MM-dd HH:mm:ss"
          type="datetimerange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          :default-time="['00:00:00','23:59:59']"
        ></el-date-picker>
      </el-form-item>
      
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="list">
      <el-table-column label="车位编号" align="center" prop="parkspaceName" width="150px"/>
      <el-table-column label="设备SN" align="center" prop="deviceSn" width="150px" />
      <el-table-column label="车位状态" align="center" prop="parkspaceStatus" width="150px">
        <template slot-scope="{row}">
          <dict-tag :options="dict.type.berth_park_status" :value="row.parkspaceStatus"/>
        </template>
      </el-table-column>
      <el-table-column label="地磁状态" align="center" prop="sMs" width="150px" />
      <el-table-column label="雷达状态" align="center" prop="sRs" width="150px" />
      <el-table-column label="Flash状态" align="center" prop="sFs" width="150px" />
      <el-table-column label="蓝牙状态" align="center" prop="sBle" width="150px" />
      <!-- <el-table-column label="地磁状态" align="center" prop="car" width="150px">
        <template slot-scope="{row}">
          <dict-tag :options="dict.type.berth_park_status" :value="row.car"/>
        </template>
      </el-table-column>
      <el-table-column label="雷达状态" align="center" prop="car" width="150px">
        <template slot-scope="{row}">
          <dict-tag :options="dict.type.berth_park_status" :value="row.car"/>
        </template>
      </el-table-column>
      <el-table-column label="Flash状态" align="center" prop="car" width="150px">
        <template slot-scope="{row}">
          <dict-tag :options="dict.type.berth_park_status" :value="row.car"/>
        </template>
      </el-table-column>
      <el-table-column label="蓝牙状态" align="center" prop="car" width="150px">
        <template slot-scope="{row}">
          <dict-tag :options="dict.type.berth_park_status" :value="row.car"/>
        </template>
      </el-table-column> -->
      <el-table-column label="信号" align="center" prop="sCsq" width="150px" />
      <el-table-column label="复位次数" align="center" prop="sWdt"  width="150px"/>
      <el-table-column label="电池" align="center" prop="sBat" width="150px" />
      <el-table-column label="温度" align="center" prop="sTemp"  width="150px"/>
      <el-table-column label="耗电量" align="center" prop="sLdp" width="150px" />
      <el-table-column label="采集次数" align="center" prop="sLdrc"  width="150px"/>
      <el-table-column label="改变次数" align="center" prop="sLdcc" width="150px" />
      <el-table-column label="磁场X" align="center" prop="sMx"  width="150px"/>
      <el-table-column label="磁场Y" align="center" prop="sMy"  width="150px"/>
      <el-table-column label="磁场Z" align="center" prop="sMz"  width="150px"/>
      <el-table-column label="光感" align="center" prop="sLt"  width="150px"/>
      <el-table-column label="红外" align="center" prop="sIrv"  width="150px"/>
      <el-table-column label="运行时间" align="center" prop="sRt"  width="150px"/>
      <el-table-column label="休眠时间" align="center" prop="sSt" width="150px" />
      <el-table-column label="NB重启次数" align="center" prop="sNrsc"  width="150px"/>
      <el-table-column label="Mag次数" align="center" prop="sMfc"  width="150px"/>
      <el-table-column label="硬件版本" align="center" prop="hwVer"  width="150px"/>
      <el-table-column label="软件版本" align="center" prop="swVer"  width="150px"/>
      <el-table-column label="在线状态" align="center" prop="linkStatus" width="150px">
        <template slot-scope="{row}">
          <dict-tag :options="dict.type.comm_online_status" :value="row.linkStatus"/>
        </template>
      </el-table-column>
      <el-table-column label="更新时间" align="center" prop="updatetimeStr" width="150px" fixed="right" />
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { getList,} from "@/api/parking/equipStatusRecord";
import { listAllFaParkProject,} from "@/api/config/projectPushManage";
import { getDay,getEndStartTime,} from "@/utils/time";
export default {
  name: "EquipStatusRecord",
  dicts: ['berth_park_status','device_reason_report','device_abnormal_state','comm_online_status'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 字典表格数据
      list: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        parklotName:null,
        parkspaceName:null,
        deviceSn:null,
        parkspaceStatus:null,
        sMs:null,
        sFs:null,
        sBle:null,
        hwVer:null,
        swVer:null,
        linkStatus:null,
        dateRange:[],
      },
      proJectList:[],//项目列表数据
    };
  },
  created() {
    this.listAllFaParkProject()
  },
  methods: {
    async listAllFaParkProject(){//获取项目
      let res = await listAllFaParkProject()
      let data = res.data || []
      this.proJectList = data
      this.getList();
    },
    getInitTime(){//初始化时间
      let end = getDay(-1)
      let start = getDay(-7)
      let time = getEndStartTime([start,end])
      let queryParams = {...this.queryParams}
      queryParams.dateRange = [time.startTime3,time.endTime4]
      this.queryParams = {...queryParams}
      return queryParams.dateRange
    },
    /** 查询列表 */
    getList() {
      if(!this.queryParams.projectId) {
        let queryParamss = {...this.queryParams}
        if(!this.proJectList.length) return 
        queryParamss.projectId = this.proJectList[0].id
        this.queryParams = {...queryParamss}
      }
      this.loading = true;
      let queryParams = {...this.queryParams}
      let dateRange = queryParams.dateRange || []
      // if(!dateRange.length) dateRange = this.getInitTime()
      if(dateRange.length) {
        queryParams.startDate = dateRange[0]
        queryParams.endDate = dateRange[1]
      }
      delete queryParams.dateRange
      getList(queryParams).then(response => {
        this.list = response.rows || [];
        this.total = response.total || 0;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
  }
};
</script>